//
//  ICComEmpListTableViewCell.m
//  ICome
//
//  Created by zhangrongwu on 16/4/26.
//  Copyright © 2016年 iCom. All rights reserved.
//

#import "ICComEmpListTableViewCell.h"
#define headImageHeight 33.0

@implementation ICComEmpListTableViewCell
- (id)initWithStyle:(UITableViewCellStyle)cell reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:cell reuseIdentifier:reuseIdentifier];
    if (self) {
        [self layoutSubview];
    }
    return self;
}

- (void)layoutSubview {
    [self.selectButton mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).offset(15);
        make.centerY.equalTo(self.mas_centerY);
    }];
    
    [self.headImgView mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.selectButton.mas_right).offset(10);
        make.centerY.equalTo(self.mas_centerY);
        make.width.height.mas_equalTo(headImageHeight);
    }];
    
    [self.titleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.headImgView.mas_right).offset(6);
        make.centerY.equalTo(self.mas_centerY);
    }];
}

-(void)setModel:(ICEmpInfoModel *)model {
    _model = model;
    self.titleLabel.text = model.eName;
    NSString *URL = [ICTools getMinImageURL:(model.photoId)];
     [UIImage addAvatariamgeView:self.headImgView withUrlStr:URL witheId:model.eId withName:model.eName];
//    [self.headImgView sd_setImageWithURL:[NSURL URLWithString:URL] placeholderImage:[UIImage imageNamed:@"App_personal_headimg"]];
    self.selectButton.selected = model.select;
}

- (void)selectAction {
    if ([self.delegate respondsToSelector:@selector(emp_clickSlectButtonInCell:)]) {
        [self.delegate emp_clickSlectButtonInCell:self];
    }
}

- (UIImageView *)headImgView {
    if (!_headImgView) {
        _headImgView = [[UIImageView alloc] init];
        _headImgView.layer.masksToBounds = YES;
        _headImgView.layer.cornerRadius = 4;
//        _headImgView.layer.borderWidth = 1;
//        _headImgView.layer.borderColor = [UIColor lightGrayColor].CGColor;
        [self.contentView addSubview:_headImgView];
    }
    return _headImgView;
}

- (UILabel *)titleLabel {
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.font = [UIFont systemFontOfSize:17];
        _titleLabel.preferredMaxLayoutWidth = 200 / 375 * App_Frame_Width;
        [_titleLabel sizeToFit];
        _titleLabel.textColor = ICTEXTCOLOR_T1;
        [self.contentView addSubview:_titleLabel];
    }
    return _titleLabel;
}

- (UIButton *)selectButton {
    if (!_selectButton) {
        _selectButton = [[UIButton alloc] init];
        [_selectButton setImage:[UIImage imageNamedFromiComeSDKBundle:@"App_select_dis"] forState:UIControlStateNormal];
        [_selectButton setImage:[UIImage imageNamedFromiComeSDKBundle:@"App_select"] forState:UIControlStateSelected];
        _selectButton.userInteractionEnabled = YES;
        [_selectButton addTarget:self action:@selector(selectAction) forControlEvents:UIControlEventTouchUpInside];
        [self.contentView addSubview:_selectButton];
    }
    return _selectButton;
}

- (void)layoutSubviews {
    [super layoutSubviews];
}

@end
